<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        
        <link rel="stylesheet" href="/css/weui.min.css" />
        <link rel="stylesheet" href="/css/bootstrap.min.css" />
        <title>登录</title>
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col col-sm col-md-9 col-xs-5" style="margin:auto">
                    <div class="card" >
                        <div class="card-body">
                            <form action="#" class="login-form" novalidate >
                                <div class="form-group">
                                    <label for="username">用户名</label>
                                    <input
                                        type="text"
                                        class="form-control"
                                        id="username"
                                        required
                                    />
                                    <div class="invalid-feedback">
                                        用户名不能为空
                                      </div>
                                </div>
                                <div class="form-group">
                                    <label for="pwd">密码</label>
                                    <input
                                        type="password"
                                        class="form-control"
                                        id="pwd"
                                        required
                                    />
                                    <div class="invalid-feedback">
                                        密码不能为空
                                      </div>
                                </div>
                                <div >
                                    <button type="submit" class="btn btn-primary col col-md-2 col-xs-2" >
                                        登录
                                    </button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script src="/js/jquery-3.0.0.slim.min.js"></script>
        <script src="/js/bootstrap.min.js"></script>
        <script src="/js/weui.min.js"></script>
        <script src="/js/axios.min.js"></script>
        <script>
            $(function () {
                $(".login-form").on("submit", function(event){
                    if (!this.checkValidity()) {
                        event.preventDefault();
                        event.stopPropagation();
                        this.classList.add('was-validated');
                        return;
                    }
                    
                    axios({
                        method: "post",
                        url: "/users/login",
                        data: {
                            username: $("#username").val(),
                            pwd: $("#pwd").val()
                        }
                    }).then((res) => {
                        if(res.data.status == 1){
                            window.location = "/upfile"
                        }else{
                            weui.alert("请检查用户名或密码是否正确");
                        }
                    });
                    
                    event.preventDefault();
                    event.stopPropagation();
                    
                });
            });
        </script>
    </body>
</html>
